package com.learning.platform.dto;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * 学习统计响应DTO
 */
public class LearningStatsResponse {
    
    // 基础统计
    private Long totalStudyTimeSeconds;
    private String formattedStudyTime;
    private Integer studyDaysCount;
    private Integer continuousStudyDays;
    private Integer coursesStudied;
    private Integer notesCreated;
    
    // 每日学习数据
    private List<DailyStudyData> dailyStudyData;
    
    // 课程学习时长排行
    private List<CourseStudyTime> courseRanking;
    
    // 学习类型分布
    private Map<String, StudyTypeStats> sessionTypeStats;
    
    // 学习热力图数据（按小时）
    private List<HourlyStudyData> hourlyData;
    
    // 进度统计
    private ProgressStats progressStats;
    
    // 内部类定义
    public static class DailyStudyData {
        private LocalDate date;
        private Long studyTimeSeconds;
        private String formattedTime;
        private Integer sessionsCount;
        
        public DailyStudyData() {}
        
        public DailyStudyData(LocalDate date, Long studyTimeSeconds) {
            this.date = date;
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        
        // Getters and Setters
        public LocalDate getDate() { return date; }
        public void setDate(LocalDate date) { this.date = date; }
        public Long getStudyTimeSeconds() { return studyTimeSeconds; }
        public void setStudyTimeSeconds(Long studyTimeSeconds) { 
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        public String getFormattedTime() { return formattedTime; }
        public void setFormattedTime(String formattedTime) { this.formattedTime = formattedTime; }
        public Integer getSessionsCount() { return sessionsCount; }
        public void setSessionsCount(Integer sessionsCount) { this.sessionsCount = sessionsCount; }
    }
    
    public static class CourseStudyTime {
        private Long courseId;
        private String courseTitle;
        private Long studyTimeSeconds;
        private String formattedTime;
        private BigDecimal progressPercentage;
        
        public CourseStudyTime() {}
        
        public CourseStudyTime(Long courseId, Long studyTimeSeconds) {
            this.courseId = courseId;
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        
        // Getters and Setters
        public Long getCourseId() { return courseId; }
        public void setCourseId(Long courseId) { this.courseId = courseId; }
        public String getCourseTitle() { return courseTitle; }
        public void setCourseTitle(String courseTitle) { this.courseTitle = courseTitle; }
        public Long getStudyTimeSeconds() { return studyTimeSeconds; }
        public void setStudyTimeSeconds(Long studyTimeSeconds) { 
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        public String getFormattedTime() { return formattedTime; }
        public void setFormattedTime(String formattedTime) { this.formattedTime = formattedTime; }
        public BigDecimal getProgressPercentage() { return progressPercentage; }
        public void setProgressPercentage(BigDecimal progressPercentage) { this.progressPercentage = progressPercentage; }
    }
    
    public static class StudyTypeStats {
        private String sessionType;
        private Long sessionCount;
        private Long studyTimeSeconds;
        private String formattedTime;
        private BigDecimal percentage;
        
        public StudyTypeStats() {}
        
        public StudyTypeStats(String sessionType, Long sessionCount, Long studyTimeSeconds) {
            this.sessionType = sessionType;
            this.sessionCount = sessionCount;
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        
        // Getters and Setters
        public String getSessionType() { return sessionType; }
        public void setSessionType(String sessionType) { this.sessionType = sessionType; }
        public Long getSessionCount() { return sessionCount; }
        public void setSessionCount(Long sessionCount) { this.sessionCount = sessionCount; }
        public Long getStudyTimeSeconds() { return studyTimeSeconds; }
        public void setStudyTimeSeconds(Long studyTimeSeconds) { 
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        public String getFormattedTime() { return formattedTime; }
        public void setFormattedTime(String formattedTime) { this.formattedTime = formattedTime; }
        public BigDecimal getPercentage() { return percentage; }
        public void setPercentage(BigDecimal percentage) { this.percentage = percentage; }
    }
    
    public static class HourlyStudyData {
        private Integer hour;
        private Long sessionCount;
        private Long studyTimeSeconds;
        private String formattedTime;
        
        public HourlyStudyData() {}
        
        public HourlyStudyData(Integer hour, Long sessionCount, Long studyTimeSeconds) {
            this.hour = hour;
            this.sessionCount = sessionCount;
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        
        // Getters and Setters
        public Integer getHour() { return hour; }
        public void setHour(Integer hour) { this.hour = hour; }
        public Long getSessionCount() { return sessionCount; }
        public void setSessionCount(Long sessionCount) { this.sessionCount = sessionCount; }
        public Long getStudyTimeSeconds() { return studyTimeSeconds; }
        public void setStudyTimeSeconds(Long studyTimeSeconds) { 
            this.studyTimeSeconds = studyTimeSeconds;
            this.formattedTime = formatDuration(studyTimeSeconds);
        }
        public String getFormattedTime() { return formattedTime; }
        public void setFormattedTime(String formattedTime) { this.formattedTime = formattedTime; }
    }
    
    public static class ProgressStats {
        private Integer totalLessonsEnrolled;
        private Integer lessonsCompleted;
        private BigDecimal overallProgressPercentage;
        private Integer coursesCompleted;
        private Integer examsCompleted;
        private Integer certificatesEarned;
        
        // Getters and Setters
        public Integer getTotalLessonsEnrolled() { return totalLessonsEnrolled; }
        public void setTotalLessonsEnrolled(Integer totalLessonsEnrolled) { this.totalLessonsEnrolled = totalLessonsEnrolled; }
        public Integer getLessonsCompleted() { return lessonsCompleted; }
        public void setLessonsCompleted(Integer lessonsCompleted) { this.lessonsCompleted = lessonsCompleted; }
        public BigDecimal getOverallProgressPercentage() { return overallProgressPercentage; }
        public void setOverallProgressPercentage(BigDecimal overallProgressPercentage) { this.overallProgressPercentage = overallProgressPercentage; }
        public Integer getCoursesCompleted() { return coursesCompleted; }
        public void setCoursesCompleted(Integer coursesCompleted) { this.coursesCompleted = coursesCompleted; }
        public Integer getExamsCompleted() { return examsCompleted; }
        public void setExamsCompleted(Integer examsCompleted) { this.examsCompleted = examsCompleted; }
        public Integer getCertificatesEarned() { return certificatesEarned; }
        public void setCertificatesEarned(Integer certificatesEarned) { this.certificatesEarned = certificatesEarned; }
    }
    
    // 工具方法
    private static String formatDuration(Long seconds) {
        if (seconds == null || seconds <= 0) {
            return "0分钟";
        }
        
        long hours = seconds / 3600;
        long minutes = (seconds % 3600) / 60;
        long secs = seconds % 60;
        
        StringBuilder sb = new StringBuilder();
        if (hours > 0) {
            sb.append(hours).append("小时");
        }
        if (minutes > 0) {
            sb.append(minutes).append("分钟");
        }
        if (hours == 0 && minutes == 0 && secs > 0) {
            sb.append(secs).append("秒");
        }
        
        return sb.length() > 0 ? sb.toString() : "0分钟";
    }
    
    // Constructors
    public LearningStatsResponse() {}
    
    // Main getters and setters
    public Long getTotalStudyTimeSeconds() {
        return totalStudyTimeSeconds;
    }
    
    public void setTotalStudyTimeSeconds(Long totalStudyTimeSeconds) {
        this.totalStudyTimeSeconds = totalStudyTimeSeconds;
        this.formattedStudyTime = formatDuration(totalStudyTimeSeconds);
    }
    
    public String getFormattedStudyTime() {
        return formattedStudyTime;
    }
    
    public void setFormattedStudyTime(String formattedStudyTime) {
        this.formattedStudyTime = formattedStudyTime;
    }
    
    public Integer getStudyDaysCount() {
        return studyDaysCount;
    }
    
    public void setStudyDaysCount(Integer studyDaysCount) {
        this.studyDaysCount = studyDaysCount;
    }
    
    public Integer getContinuousStudyDays() {
        return continuousStudyDays;
    }
    
    public void setContinuousStudyDays(Integer continuousStudyDays) {
        this.continuousStudyDays = continuousStudyDays;
    }
    
    public Integer getCoursesStudied() {
        return coursesStudied;
    }
    
    public void setCoursesStudied(Integer coursesStudied) {
        this.coursesStudied = coursesStudied;
    }
    
    public Integer getNotesCreated() {
        return notesCreated;
    }
    
    public void setNotesCreated(Integer notesCreated) {
        this.notesCreated = notesCreated;
    }
    
    public List<DailyStudyData> getDailyStudyData() {
        return dailyStudyData;
    }
    
    public void setDailyStudyData(List<DailyStudyData> dailyStudyData) {
        this.dailyStudyData = dailyStudyData;
    }
    
    public List<CourseStudyTime> getCourseRanking() {
        return courseRanking;
    }
    
    public void setCourseRanking(List<CourseStudyTime> courseRanking) {
        this.courseRanking = courseRanking;
    }
    
    public Map<String, StudyTypeStats> getSessionTypeStats() {
        return sessionTypeStats;
    }
    
    public void setSessionTypeStats(Map<String, StudyTypeStats> sessionTypeStats) {
        this.sessionTypeStats = sessionTypeStats;
    }
    
    public List<HourlyStudyData> getHourlyData() {
        return hourlyData;
    }
    
    public void setHourlyData(List<HourlyStudyData> hourlyData) {
        this.hourlyData = hourlyData;
    }
    
    public ProgressStats getProgressStats() {
        return progressStats;
    }
    
    public void setProgressStats(ProgressStats progressStats) {
        this.progressStats = progressStats;
    }
}
